//
//  Dog1.m
//  OCTest
//
//  Created by 韩艳锋 on 2018/4/27.
//  Copyright © 2018年 韩艳锋. All rights reserved.
//

#import "Dog1.h"
#import <objc/runtime.h>
#import <objc/message.h>

@implementation Dog1
//+ (void)load {
//    Method me1 = class_getInstanceMethod([Dog1 class], NSSelectorFromString(@"encodeWithCoder:"));
//    Method me2 = class_getInstanceMethod([Dog1 class], NSSelectorFromString(@"HF_encodeWithCoder:"));
//    method_exchangeImplementations(me2, me1);
//
//}

- (void)encodeWithCoder:(NSCoder *)aCoder {

    u_int count;
    objc_property_t * properties = class_copyPropertyList([self class], &count);
    
    for (int i = 0; i < count; i++) {
        const char * properttName = property_getName(properties[i]);
        const char * attributes = property_getAttributes(properties[i]);
        NSString * name = [NSString stringWithCString:properttName encoding:NSUTF8StringEncoding];
        NSString * value = [NSString stringWithCString:attributes encoding:NSUTF8StringEncoding];
        [aCoder encodeObject:value forKey:name];
    }
}

@end
